using UnityEngine;

public class Hurricane : MonoBehaviour
{
	public float range = 10f;

	public Vector3 force = new Vector3(5f, 5f, 1f);

	private Transform tr;

	private AudioSource audioSource;

	private Rigidbody tRigidbody;

	private void Start()
	{
		tr = base.transform;
		tRigidbody = tr.root.GetComponent<Rigidbody>();
		audioSource = GetComponent<AudioSource>();
		LeanTween.value(base.gameObject, 0f, 0.9f, 1.5f).setOnUpdate(delegate(float v)
		{
			audioSource.volume = v;
		});
	}

	private void Update()
	{
		tr.rotation = Quaternion.identity;
	}

	public void Stop()
	{
		ParticleSystem[] componentsInChildren = GetComponentsInChildren<ParticleSystem>();
		ParticleSystem[] array = componentsInChildren;
		foreach (ParticleSystem particleSystem in array)
		{
			particleSystem.Stop(withChildren: true, ParticleSystemStopBehavior.StopEmitting);
		}
		LeanTween.value(base.gameObject, audioSource.volume, 0f, 1.5f).setOnUpdate(delegate(float v)
		{
			audioSource.volume = v;
		});
	}

	private void FixedUpdate()
	{
		StateManager.specialEnergy -= 0.2f;
		tRigidbody.AddRelativeTorque(0f, 0.005f, 0f);
		GameObject[] array = GameObject.FindGameObjectsWithTag("AI");
		GameObject[] array2 = array;
		Vector3 vector = default(Vector3);
		foreach (GameObject gameObject in array2)
		{
			if ((bool)gameObject)
			{
				Vector3 position = gameObject.transform.position;
				Vector3 position2 = tr.position;
				float num = 0.1f + Mathf.Abs(position2.x - position.x);
				Vector3 position3 = tr.position;
				float num2 = num + Mathf.Abs(position3.z - position.z);
				if (!(num2 > range))
				{
					Vector3 position4 = tr.position;
					float x = position4.x - position.x;
					Vector3 position5 = tr.position;
					vector = new Vector3(x, 0f, position5.z - position.z);
					Rigidbody component = gameObject.GetComponent<Rigidbody>();
					component.AddForce(Vector3.Cross(tr.up, vector) * force.z / Mathf.Clamp(num2 * num2, 1f, 1000f) + vector * force.x / Mathf.Clamp(num2 * num2, 1f, 1000f) + Vector3.up * force.y / Mathf.Clamp(num2, 1f, 500f), ForceMode.Force);
					component.AddRelativeTorque(vector * 2f, ForceMode.Force);
				}
			}
		}
	}
}
